import nfc from '../dxmodules/dxNfc.js'
import std from '../dxmodules/dxStd.js'
import logger from '../dxmodules/dxLogger.js'

const id = 'nfc'

// NFC initialization
nfc.init(id)

// NFC regular card callback registration
nfc.cbRegister(id)

// NFC PSAM card registration callback
nfc.psamCbRegister(id)

std.setInterval(() => {
    if (!nfc.msgIsEmpty(id)) {
        // Print card number data
        let res = nfc.msgReceive(id);
        logger.info(res);
    }
}, 10)

std.setInterval(() => {
    // Determine if there is a card
    if (nfc.isCardIn(id)) {
        // Read M1 card data
        nfc.m1cardReadSector(0, 2, 0, 4, [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF], 0x60, id)
        // Write data to m1 card
        nfc.m1cardWriteBlk(0, 5, 0, 2, [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF], 0x61, [0x11, 0x22, 0x33], id)
    }
}, 10)
